"use strict";
const { Model, FLOAT } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Staff extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // Staff.hasMany(models.Contract, {
      //   // onDelete: 'cascade',
      //   // OnUpdate: 'cascade',
      //   foreignKey: 'staff_id',

      // })
      Staff.hasMany(models.Problems, {
        foreignKey: "staff_id",
        // onDelete: 'cascade',

        // OnUpdate: 'cascade',
      });
      Staff.belongsTo(models.department, {
        foreignKey: "department_id",
        onDelete: "CASCADE",
        OnUpdate: "CASCADE",
      });
      Staff.hasMany(models.Project, {
        foreignKey: "manager_id",
      });
      Staff.hasMany(models.Contract, {
        foreignKey: "creator_id",
        as: "creator",
      });
      Staff.hasMany(models.Implement, {
        foreignKey: "implementor_id",
      });
      Staff.hasMany(models.Implement, {
        foreignKey: "technician_id",
      });
      Staff.hasMany(models.Shop, {
        foreignKey: "purchaser_id",
      });
      Staff.hasMany(models.ContractPayment, {
        foreignKey: "manager_id",
      });
      Staff.hasMany(models.Opportunity, {
        foreignKey: "staff_id",
      });
      Staff.hasMany(models.Opportunity, {
        foreignKey: "checker_id",
      });
      Staff.hasMany(models.message, {
        foreignKey: "creator_id",
      });
      // Staff.hasMany(models.Client,{
      //   foreignKey:'checker_id',
      //   unique:false

      // })
      // Staff.hasMany(models.Project,{
      //   foreignKey:'checker_id',

      // })
      // Staff.hasMany(models.Contract,{
      //   foreignKey:'checker_id'
      // })
      // Staff.hasMany(models.Factory,{
      //   foreignKey:'checker_id',

      // })
      // Staff.hasMany(models.Product,{
      //   foreignKey:'checker_id',

      // })
      // Staff.hasMany(models.Shop,{
      //   foreignKey:'checker_id'
      // })
      // Staff.hasMany(models.Implement,{
      //   foreignKey:'checker_id'
      // })
      // Staff.hasMany(models.Service,{
      //   foreignKey:'checker_id'
      // })

      // define association here
    }
  }
  Staff.init(
    {
      staff_name: DataTypes.STRING,
      staff_age: DataTypes.INTEGER,
      // staff_month_salary: DataTypes.FLOAT,
      // staff_year_salary: DataTypes.FLOAT,
      staff_phone: {
        type: DataTypes.STRING,
        // unique:true
      },
      staff_email: {
        type: DataTypes.STRING,
        // unique:true
      },
      staff_position: DataTypes.STRING, //岗位
      staff_competence: DataTypes.STRING, //职责
      department_id: DataTypes.INTEGER,
      password: DataTypes.STRING,
      // is_admin:{
      //   type:DataTypes.BOOLEAN,
      //   defaultValue:false,
      // },
      role: DataTypes.STRING, //角色：部员/部长
      level: {
        //级别：1代表普通员工，2代表部长，3代表公司老板
        type: DataTypes.INTEGER,
        defaultValue: 1,
      },
    },
    {
      sequelize,
      modelName: "Staff",
      tableName: "staffs",
    }
  );
  return Staff;
};
